<template>
    <div class="order-report">
        <div class="report-table-top-title">投影仪管理</div>
        <div class="report-table-form1">
            <el-form
                ref="form"
                size="small"
                inline
                :model="searchParam"
                label-width="80px"
            >
              <el-form-item label="委外SN码:" prop="originNo">
                    <el-input
                        class="items"
                        v-model="searchParam.originNo"
                        placeholder
                        size="small"
                        suffix-icon="el-icon-search"
                    ></el-input>
                </el-form-item>
                <el-form-item label="视易SN码:" prop="oemNo">
                    <el-input
                        class="items"
                        v-model="searchParam.oemNo"
                        placeholder
                        size="small"
                        suffix-icon="el-icon-search"
                    ></el-input>
                </el-form-item>
                <el-form-item label="录入时间:" prop="createDate">
                    <!-- <el-date-picker
                        v-model="searchParam.createDate"
                        type="date"
                        size="small"
                        class="items"
                        value-format="yyyy-MM-dd"
                        format="yyyy-MM-dd"
                        placeholder="选择日期时间"
                    >
                    </el-date-picker> -->
                    <el-date-picker
                        v-model="searchParam.startDateTime"
                        type="datetime"
                        size="small"
                        class="items"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间"
                    >
                    </el-date-picker>

                    <span>至:</span>
                    <el-date-picker
                        v-model="searchParam.endDateTime"
                        type="datetime"
                        class="items"
                        size="small"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间"
                    >
                    </el-date-picker>
                </el-form-item>

              
                <el-form-item label="设备类型:" prop="productNo">
                    <div class="flex">
                        <el-select
                            v-model="searchParam.productNo"
                            class="items"
                            placeholder="请选择"
                            size="small"
                        >
                            <el-option label="全部" value=""></el-option>
                            <el-option
                                v-for="(item, index) in typeList"
                                :key="index"
                                :label="item"
                                :value="item"
                            ></el-option>
                        </el-select>
                        <el-button
                            type="primary"
                            style="margin-left: 10px"
                            size="small"
                            @click="reSearch"
                            >搜索</el-button
                        >
                        <el-upload
                            action
                            :show-file-list="false"
                            ref="upload"
                            :http-request="fnUploadRequest"
                            :limit="1"
                            accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                        >
                            <el-button
                                slot="trigger"
                                size="small"
                                plain
                                type="primary"
                                style="margin: 0 10px"
                                @click="$refs.upload.clearFiles()"
                                >导入</el-button
                            >
                        </el-upload>
                        <el-button
                            size="mini"
                            plain
                            type="primary"
                            :loading="isDownLoading"
                            class="el-button-1"
                            @click="exportTemplate"
                            >导入模板下载</el-button
                        >
                    </div>
                </el-form-item>
            </el-form>
        </div>
        <div class="page-padding-gray-small"></div>
        <div class="report-table-wrapper">
            <el-table
                :header-cell-style="headerCellStyle"
                size="small"
                :data="tabData"
                border
                style="width: 100%"
            >
                <el-table-column
                    prop="originNo"
                    label="委外SN码（原始序列号）"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="oemNo"
                    label="视易SN码（OEM序列号）"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="productNo"
                    label="设备型号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="createDate"
                    label="录入时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
            </el-table>
        </div>
        <!-- 分页 -->
        <div class="report-table-block">
            <div class="report-table-block-in">
                <el-pagination
                    background
                    :current-page.sync="currentPage"
                    @current-change="handleCurrentChange"
                    :page-size="pageSize"
                    layout="prev, pager, next, total"
                    :total="totalNum"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
export default {
    data: function () {
        return {
            typeList: [],
            row: null,
            isDownLoading: false, // 导入模板加载
            loading: false,
            isShow: false,
            searchParam: {
                productNo: '',
                startDateTime: '',
                endDateTime: '',
                originNo: '',
                oemNo: ''
            },
            agentList: [],
            currentPage: 1,
            pageSize: 10,
            totalNum: 0,
            tabData: [],
            size: 100
        }
    },
    mounted () {
    },
    created () {
        // this.getAllAgent()
        this.getTypeList()
        this.getList()
    },
    watch: {
    },
    props: {
        underLine: null
    },
    computed: {
        ip () {
            return this.$store.state.IP
        }
    },
    methods: {
        async exportTemplate () {
            this.isDownLoading = true
            let res = await this.$http.get(this.$store.state.IP + '/terminalSn/exportSn', {
            })
            let response = res.data
            if (response.ret === '0') {
                this.isDownLoading = false
                let name = this.checkBrowser()
                if (name === '360') {
                    window.open(response.res)
                } else {
                    window.location = response.res
                }
            } else {
                this.isDownLoading = false
            }
        },
        async getTypeList () {
            let res = await this.$http.get(this.$store.state.IP + '/terminalSn/productNo', {
            })
            let response = res.data
            if (response.ret === '0') {
                this.typeList = response.res
            }
        },
        getFileType: function (filePath) {
            var startIndex = filePath.lastIndexOf('.')
            if (startIndex !== -1) {
                return filePath.substring(startIndex + 1, filePath.length).toLowerCase()
            } else {
                return ''
            }
        },
        beforeUpload (file) {
            let fileType = this.getFileType(file.name)
            console.log(fileType)
            if (fileType !== 'xls' && fileType !== 'xlsx') {
                this.$message.warning('请上传.xlsx或者.xls格式文件')
                return false
            }
            return true
        },
        async fnUploadRequest (option) {
            console.log(option)
            let file = option.file
            if (!this.beforeUpload(file)) {
                this.$refs.upload.uploadFiles = []
                return false
            }
            console.log('65666')
            let formData = new FormData()
            formData.append('file', file)
            let res = await this.$http.post(this.$store.state.IP + '/terminalSn/importSn', formData)
            let response = res.data
            if (response.ret === '0') {
                console.log(response)
                this.$message({
                    message: '导入成功',
                    type: 'success'
                })
                this.getList()
            }
        },
        handleCurrentChange (page) {
            // 换页
            this.currentPage = page
            this.getList()
        },
        reSearch () {
            this.currentPage = 1
            this.getList()
        },
        getList () {
            if (this.searchParam.endDateTime) {
                if (this.searchParam.endDateTime < this.searchParam.startDateTime) {
                    return this.$message({
                        message: '开始时间不能大于结束时间',
                        type: 'warning'
                    })
                }
            }
            // 获取 所有 服务列表
            this.$http.post(this.$store.state.IP + '/terminalSn/terminalSnList', {
                ...this.searchParam,
                page: this.currentPage - 1,
                size: this.pageSize
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                response = response.body
                this.tabData = []
                if (response.ret === '0') {
                    this.tabData = response.res.list
                    this.totalNum = response.res.total
                }
                if (response.ret !== '0') {
                    console.log('调用获取所有代理商失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
.flex
    display: flex

.order-report
    width: 100%
    background: #fff
    min-height: calc(100vh - 65px)
    position: relative

    .report-table-top-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px
        background: #f1f0f5

    .report-table-form1
        width: 100%
        min-height: 40px
        padding: 16px 0 0 22px
        box-sizing: border-box
        background: #fff
        overflow: hidden

        .report-table-form1-line
            min-height: 32px
            margin-bottom: 16px

            .report-table-form1-item
                display: inline-block
                vertical-align: top
                height: 32px
                margin-right: 15px
                line-height: 32px

                &.word
                    margin-right: 0

                &.samll
                    font-size: 15px
                    text-align: left

                &.big
                    margin-right: 100px

    .report-table-block
        width: 100%
        padding-top: 22px
        height: 50px
        background: #fff
        box-sizing: border-box

        .report-table-block-in
            float: right
            padding-right: 17px

    .page-padding-gray-small
        width: 100%
        height: 22px
        background: #f1f0f5

    .page-padding
        width: 100%
        height: 20px
        background: #fff

    .report-table-total
        width: 100%
        font-size: 16px
        color: #409EFF
        padding: 22px
        margin-top: 22px
        box-sizing: border-box
        background: #fff

    .page-all-loading
        position: fixed
        top: 55%
        left: 40%
        width: 200px

.title
    display: inline-block
    min-width: 120px
    text-align: right
    font-weight: bold
    line-height: 35px

.value
    display: inline-block
    line-height: 35px
    min-width: 150px

.items
    width: 190px

.item
    margin-bottom: 0px
</style>

